/**
 *
 * Copyright 2015 RSVP Technologies Inc. All rights reserved.
 * LRUCache.java
 *
 */
package com.gfinal.algorithm;

import java.util.LinkedHashMap;

/**
 * LRU缓存算法
 *@author Gao Yudong (gyd@nbicc.com) 
 * @param <K>
 * @param <V>
 *@date 2015-3-4
 */
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
	private static final long serialVersionUID = 681039186445896814L;
	
	private int maxEntries = 5;

	public LRUCache(int maxEntries) {
		super(16, 0.75f, true);
		this.maxEntries = maxEntries;
	}
	
	public LRUCache() {
		super(16, 0.75f, true);
	}

	@Override
	protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
		return size() > maxEntries;
	}
	
}
